package cn.yzking.studentmanagement.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

public class SPSaveAccount {
    public static Map<String, String> getUserInfo(Context context) {
        SharedPreferences sp = context.getSharedPreferences("user_info", Context.MODE_PRIVATE);
        String username = sp.getString("username", null);
        String password = sp.getString("password", null);

        return new HashMap<>() {
            {
                put("username", username);
                put("password", password);
            }
        };
    }

    public static void saveUserInfo(Context context, String username, String password) {
        SharedPreferences.Editor edit = context.getSharedPreferences("user_info", Context.MODE_PRIVATE).edit();
        edit.putString("username", username);
        edit.putString("password", password);
        edit.apply();
    }

    public static void removeUserInfo(Context context) {
        SharedPreferences.Editor editor = context.getSharedPreferences("user_info", Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.apply();
    }
}
